/**
 * 龟兔赛跑的例子
 */
public class TestThread04 implements Runnable {

    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {

            //模拟兔子的跑步速度
            if (Thread.currentThread().getName() == "兔子") {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //兔子跑到80米的时候睡了一觉
                if (i==80){
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(Thread.currentThread().getName()+"跑了"+i+"米");
            }

            //模拟乌龟的跑步速度
            if (Thread.currentThread().getName() == "乌龟") {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"跑了"+i+"米");
            }

            if (i==100){
                System.out.println(Thread.currentThread().getName()+"到达了终点！！！！！！！");
                break;
            }
        }
    }

    public static void main(String[] args) {
        TestThread04 testThread04 = new TestThread04();
        new Thread(testThread04,"兔子").start();
        new Thread(testThread04,"乌龟").start();
    }
}